package GUI;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

class Demo1 extends JFrame {
	public Demo1()
	{
		this.setTitle("登录界面");
		this.setSize(500,500);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setResizable(false);
		JPanel jPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,100,20));		//创建面板
		jPanel.addMouseListener(new MouseListener() {
			public void mouseReleased(MouseEvent e) {}	
			public void mousePressed(MouseEvent e) {}
			public void mouseExited(MouseEvent e) {}
			public void mouseEntered(MouseEvent e) {}
			public void mouseClicked(MouseEvent e) {}
		});
		JLabel j=new JLabel("账号");						//
		j.setForeground(Color.red);						//设置颜色
		j.setFont(new Font("楷体",Font.BOLD,20));			//设置字体和大小
		JTextField field=new JTextField(15);			//账号输入栏
		field.addKeyListener(new KeyListener() {
			@Override
			public void keyPressed(KeyEvent e) {		//按下键盘
				// TODO 自动生成的方法存根
				char keychar=e.getKeyChar();
				System.out.print(keychar);}
			public void keyReleased(KeyEvent e) {}
			public void keyTyped(KeyEvent e) {}});
		JLabel jLabel=new JLabel("密码");					//
		jLabel.setForeground(Color.red);				//设置颜色
		jLabel.setFont(new Font("楷体",Font.BOLD,20));	//设置字体大小和颜色
		JPasswordField jPasswordField=new JPasswordField(15);//密码输入栏
		jPasswordField.addKeyListener(new KeyListener() {
			public void keyTyped(KeyEvent e) {}
			public void keyReleased(KeyEvent e) {}
			public void keyPressed(KeyEvent e) {
				// TODO 自动生成的方法存根
				char keychar=e.getKeyChar();				
				System.out.print(keychar);}	});
		//JTextField field2=new JTextField(15);
		JButton jButton=new JButton("登录");				//登录按钮
		JButton jButton1=new JButton("注册");
		JButton jButton2=new JButton("取消");
		jButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// TODO 自动生成的方法存根
				String string=field.getText();
				String string2=new String(jPasswordField.getPassword());
				if(!string.matches("\\w+\\d*")||(!string2.matches("\\w+\\d*")))
				{
					JOptionPane.showMessageDialog(null,"账号密码只能由字母数字组成",
							"登录提示",JOptionPane.ERROR_MESSAGE);
				}
				else {
					JOptionPane.showConfirmDialog(null,"登录成功","登录提示",JOptionPane.PLAIN_MESSAGE);
					dispose();
				}
			}
		});
		jButton1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// TODO 自动生成的方法存根
				String string=field.getText();
				String string2=new String(jPasswordField.getPassword());
				if(!string.matches("\\w+\\d*")||(!string2.matches("\\w+\\d*")))
				{
					JOptionPane.showConfirmDialog(null,"账号密码只能由字母数字组成",
							"登录提示",JOptionPane.ERROR_MESSAGE);
				}
				else {
					JOptionPane.showConfirmDialog(null,"注册成功","注册提示",JOptionPane.PLAIN_MESSAGE);
					dispose();
				}
			}
		});
		jPanel.add(j);
		jPanel.add(field);
		jPanel.add(jLabel);
		jPanel.add(jPasswordField);
		jPanel.add(jButton);
		jPanel.add(jButton1);
		jPanel.add(jButton2);
		JMenuBar jbar=new JMenuBar();
		JMenu jMenu=new JMenu("菜单");
		JMenu jMenu1=new JMenu("帮助");
		JMenuItem jMenuItem=new JMenuItem("没有菜单");
		JMenuItem jMenuItem1=new JMenuItem("没有帮助");
		jbar.add(jMenu);
		jbar.add(jMenu1);
		jMenu.add(jMenuItem);
		jMenu1.add(jMenuItem1);
		this.setJMenuBar(jbar);
		this.add(jPanel);
		this.setVisible(true);
	}
}
public class gui1
{
	public static void main(String [] args)
	{
		Demo1 demo1=new Demo1();
	}
}